<template>
    <div>
        <div class="mainBox">
            <div style="display: flex;align-items: center;">
                <!-- <el-input v-model="name" placeholder="模板名称"></el-input>
                <el-select v-model="schoolindex" placeholder="绑定考试">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                <el-select v-model="schoolindex" placeholder="考号类型">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                <el-select v-model="schoolindex" placeholder="模板类型">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                <el-select v-model="schoolindex" placeholder="创建人">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select> -->
            </div>
            <div>
                <el-button type="primary" @click="addnewschool">单个添加</el-button>
                <el-button type="primary" @click="copyexamclickbox">名单复用</el-button>
                <el-button type="primary" style="background:#D54941;border-color:#D54941" @click="batchboxdelete">批量删除</el-button>
            </div>
        </div>
        <div style="padding:15px;background:#fff;border-radius: 10px;">
            <el-table
                class="custom-table"
                ref="multipleTable"
                :data="modellist"
                tooltip-effect="dark"
                style="width: 100%"
                stripe
                @selection-change="handleSelectionChange"
                :header-cell-style="{ background: '#D8E4F0', color: '#2A303B',fontWeight:'500' }">
                <el-table-column
                    type="selection"
                    width="55">
                </el-table-column>
                <el-table-column
                    prop="itemCaseFlagName"
                    label="模板名称">
                </el-table-column>
                <el-table-column
                    prop="nav6name"
                    label="绑定考试">
                </el-table-column>
                <el-table-column
                    label="考号类型 "
                    prop="status">
                </el-table-column>
                <el-table-column
                    label="图像类型"
                    prop="status">
                </el-table-column>
                <el-table-column
                    label="创建人"
                    prop="username">
                </el-table-column>
                <el-table-column
                    label="创建时间"
                    prop="status">
                    <template slot-scope="scope">
                        {{scope.row.createDate?scope.row.createDate:'-'}}
                    </template>
                </el-table-column>
                <el-table-column
                    fixed="right"
                    label="操作"
                    align="center"
                    width="210"> 
                    <template slot-scope="scope">
                        <div style="display: flex;" class="scopednr">
                            <b @click="bindmodel(scope.row)">绑定模板</b>
                            <b @click="editExamschool(scope.row)">制作模板</b>
                            <b @click="deletepadth(scope.row.itemCaseFlagId)">删除</b>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="examfooter">
                <div class="examFootercontent">
                    <div>
                        <span class="totaldata">共<i>{{multipleSelection.length}}</i>条数据</span>
                    </div>
                    <!-- <div>
                        <el-pagination
                            background
                            @current-change="handleCurrentChange"
                            :page-sizes="[20, 50,100]"
                            @size-change="handleSizeChange"
                            :page-size="pageSize"
                            layout="sizes, prev, pager, next"
                            :total="total">
                        </el-pagination>
                    </div> -->
                </div>
            </div>
        </div>
        <!-- 新增考试 -->
		<addModel v-if="addSchoolshow" @addSchoolclick="addSchoolclick" :tabnumber="tabnumber"></addModel>
        <!-- 创建复用考试 -->
		<examCopy v-if="examCopyIshow" @copyexamclick="copyexamclick" :type="3"></examCopy>
        <!-- 创建复用考试 -->
		<bindModel v-if="bindmodelshow" :nav6name="nav6name" :nav6id="nav6id" :examnavid="examnavid" @bindmodelclick="bindmodelclick"></bindModel>
    </div>
</template>

<script>
import addModel from '../../../components/model/addmodel.vue'
import examCopy from '../../../components/model/copymodel.vue' 
import bindModel from '../../../components/model/bindmodel.vue' 
import { modelItemcaselist,batchdeletemodelcard } from '../../../api/api.js'
export default {
    data() {
        return {
            modellist: [{}], // 表格数据
            addSchoolshow:false,
            examCopyIshow:false,
            uploadishow:false,
            passwordshow:false,
            bindmodelshow:false,
            nav6name:'',
            nav6id:'',
            multipleSelection:[]
        }
    },
    computed: {
        examId() {
            return this.$store.state.examId;
        }
    },
    watch: {
    	examId(newVal) {
            if (newVal) {
                this.examnavid = newVal;
                // this.overviewlist(newVal);
                this.modelistclick(newVal)
                this.$store.commit('setExamId', ''); // 重置状态
            }
        }	
    },
    mounted() {
        this.examcontent = JSON.parse(sessionStorage.getItem('examContent'))
         this.examnavid = this.examcontent.nav5id
        this.modelistclick(this.examcontent.nav5id)
    },
    methods: {
        //新增考试
        addnewschool(){
            this.addSchoolshow = true
        },
        addSchoolclick(){
            this.addSchoolshow = false
            this.modelistclick(this.examnavid)
        },
        editExamschool(con){
            this.$router.push('/templateinformation?modelid='+con.itemCaseFlagId+'&nav6id='+con.nav6id)
        },
        copyexamclick(){
            this.examCopyIshow = false
            this.modelistclick(this.examnavid)
        },
        copyexamclickbox(){
            this.examCopyIshow = true
        },
        bindmodel(con){
            this.bindmodelshow = true
            this.nav6id = con.nav6id
            this.nav6name = con.nav6name
        },
        bindmodelclick(){
            this.bindmodelshow = false
            this.modelistclick(this.examnavid)
        },
        //获取模板
        modelistclick(id){
            let obj = {
                nav5id:id
            }
            modelItemcaselist(obj).then(res=>{
                if(res.code==0){
                    this.modellist = res.obj
                }else{
                    this.$message({
                        message: res.msg,
                        type: 'error'
                    });
                }
            })
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //单个删除
        deletepadth(id){
            let obj=[id]
            this.deletepulick(obj)
        },
        //批量删除
        batchboxdelete(){
            let obj = this.multipleSelection.map(item=>item.itemCaseFlagId)
            this.deletepulick(obj)
        },
        //删除模板
        deletepulick(id){
            if(id.length==0){
                this.$message({
                    message: '请选择要删除的文件',
                    type: 'error'
                });
                return
            }
            let obj = {
                itemcaseflagids:id
            }
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                    batchdeletemodelcard(obj).then(res=>{
                        if(res.code==0){
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.modelistclick(this.examcontent.nav5id) 
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'error'
                            });
                        }
                    })
                    
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
             });
        }
    },
    components: {
        addModel,examCopy,bindModel
    }
}
</script>

<style scoped>
.mainBox{
    background:#fff;
    margin-bottom:15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding:15px;
}
.mainBox >>> .el-button{
    background:#366EF4;
    border:solid 1px #366EF4;
    height:36px;
}
.mainBox >>> .el-select .el-input__inner, .mainBox >>> .el-input__inner{
	 width:150px; 
     margin-left:4px;
     border-radius: 10px;
     height:36px;
}
.mainBox >>> .el-input__icon{
    line-height:36px;
}
.mainBox >>> .distpicker-address-wrapper select{
    height:35px;
    line-height:35px;
    border-radius:10px;
    font-size:14px;
    color:#999;
    border:solid 1px #DCDFE6;
}
.mainBox ul{
    display: flex;
    align-items: center;
}
.mainBox ul li{
    font-size:14px;
    margin-right:15px;
    padding:0 10px;
    line-height:36px;
    cursor: pointer;
    border-bottom:solid 2px #fff;
}
.mainBox ul li:hover,.mainBox ul li.hover{
    color:#0052D9;
    border-bottom:solid 2px #0052D9;
}
.custom-table {
	  width: 100%;
	  border: 1px solid rgba(216,228,240,0.34);
	  border-radius:10px;
	  border-right: none;
	  border-bottom:none;
	}
	
	/* 自定义表格内部元素的样式 */
	.custom-table >>> .el-table__header-wrapper th {
	  background-color: #E8F0FA;
	  height:42px;
	  padding:0;
	  text-align: center;
	  font-weight:normal
	}
	.custom-table >>> .el-table__row td {
	  height:42px;
	  padding:0;
	  text-align: center;
	  border-bottom:none;
	  border-right:solid 1px rgba(216,228,240,0.34);
	  font-size:14px;
	}
	.el-table .warning-row {
	    background: #ffffff;
	 }
	.el-table .success-row {
	    background: #D8E4F0;
	}
     .el-table .el-table__cell{
        padding:8px 0;
    }
    .examfooter{
		width:100%;
		height:54px;
		left:0;
		bottom:0;
	}
	.examFootercontent{
		margin:0 auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.examFootercontent .totaldata{
		font-size:14px;
	}
	.examFootercontent .totaldata i{
		display: inline-block;
		color:#295CFF;
		font-style: normal;
		line-height:54px;
		padding:0 3px;
	}
    .scopednr b{
        display: inline-block;
        font-weight:normal;
        margin:0 8px;
        color:#165DFF;
        cursor: pointer;
    }
    .scopednr b:last-child{
        color:#D54941
    }
</style>